package com.wushi.lenovo.asia5b.app_ui.profile.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.mvp.base.BaseMvpActivity;
import com.wushi.lenovo.asia5b.R;
import com.wushi.lenovo.asia5b.app_di.APPComponentFactory;
import com.wushi.lenovo.asia5b.app_di.profile.mvpview.MobileInfoActivityView;
import com.wushi.lenovo.asia5b.app_di.profile.presenter.MobileInfoActivityPresenter;
import com.wushi.lenovo.asia5b.app_model.other.UserInfo;
import com.wushi.lenovo.asia5b.app_model.profile.CountryModel;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by zhangyuncai on 2019/1/22.
 * 手机号信息
 */
public class MobileInfoActivity extends BaseMvpActivity<
        MobileInfoActivityView, MobileInfoActivityPresenter> implements MobileInfoActivityView {
    @BindView(R.id.tv_mobileinfo_country)
    TextView tv_mobileinfo_country;
    @BindView(R.id.tv_mobileinfo_areacode)
    TextView tv_mobileinfo_areacode;
    @BindView(R.id.tv_mobileinfo_phone)
    TextView tv_mobileinfo_phone;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_mobileinfo;
    }

    @Override
    protected void constructComponent() {
        APPComponentFactory.getAppBaseComponent().inject(this);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();

        initData();

        initEvent();
    }

    @Override
    protected void initView() {
        setView();
    }

    private void setView() {
        UserInfo userInfo = UserInfo.getUserInfo();

        //区号
        tv_mobileinfo_areacode.setText("+" + userInfo.getCalling_code());
        //手机号
        tv_mobileinfo_phone.setText(userInfo.getMobile());
    }

    @Override
    protected void initData() {
        getPresenter().getCountrys();
    }

    @Override
    protected void initEvent() {

    }

    @OnClick({
            R.id.iv_mobile_edit
    })
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_mobile_edit:
                startActivity(new Intent(this, ChangeMobileActivity.class));
                break;
            default:
                break;
        }
    }

    @Override
    public void getCountrysResult(List<CountryModel> countryModels) {
        List<CountryModel> countryModelList = countryModels;
        if (countryModelList != null) {
            for (CountryModel model : countryModelList) {
                if (model.getId() == UserInfo.getUserInfo().getCountry_id()) {
                    //国家
                    tv_mobileinfo_country.setText(model.getName());
                }
            }
        }
    }

}
